<!DOCTYPE HTML>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>复选框</title>
    <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1" >
    <meta name="generator" content="www.leipi.org" />
    <link rel="stylesheet" href="bootstrap/css/bootstrap.css">
    <!--[if lte IE 6]>
    <link rel="stylesheet" type="text/css" href="bootstrap/css/bootstrap-ie6.css">
    <![endif]-->
    <!--[if lte IE 7]>
    <link rel="stylesheet" type="text/css" href="bootstrap/css/ie.css">
    <![endif]-->
    <link rel="stylesheet" href="leipi.style.css">
    <script type="text/javascript" src="../dialogs/internal.js"></script>
    <script type="text/javascript">
	function createElement(type, name) {     
	    var element = null;     
	    try {        
	        element = document.createElement('<'+type+' name="'+name+'">');     
	    } catch (e) {}   
	    if(element==null) {     
	        element = document.createElement(type);     
	        element.name = name;     
	    } 
	    return element;     
	}
    </script>
</head>
<body>
<div class="content">
    <table class="table table-bordered table-striped table-hover">
     <tr>
        <th width="50%">控件字段&nbsp;<span class="label label-important">*</span></th>
        <th width="50%"><span>控件名称</span><span class="label label-important">*</span></th>
    </tr>
    <tr>
        <td><input id="orgname" placeholder="必填项" type="text"/> </td>
        <td><input type="text" id="orgtitle" placeholder="必填项"></td>
    </tr>
    <tr class="table table-bordered table-striped table-hover">
      <th><span>选中状态</span></th>
      <th><span>组名</span></th>
    </tr>
    <tr>
      <td>
        <label class="radio"><input id="orgchecked0" checked="checked" name="checked" type="radio"> 不选中 </label>
      <label class="radio"><input id="orgchecked1" name="checked" type="radio"> 选中 </label></td>
      <td><input id="description" name="description" type="text"/></td>
    </tr>
    <tr class="table table-bordered table-striped table-hover">
      <th><span>显示</span></th>
      <th>&nbsp;</th>
    </tr>
    <tr>
      <td>
      <input id="present0" name="present0" type="text" style="width:50px" title="值为0时的显示" value="否"/>
      /
      <input id="present1" name="present1" type="text" style="width:50px" title="值为1时的显示" value="是"/>
      </td>
      <td>&nbsp;</td>
    </tr>
    <tr>
        <th><span>只读</span></th>
        <th><span>只读类型</span></th>
    </tr>
    <tr>
        <td>
            <input id="isReadOnly" name="isReadOnly" type="checkbox" value="1" />
        </td>
        <td>
            <select id="readOnlyType">
                <option value="">不限</option>
                <option value="0">仅添加时</option>
                <option value="1">仅编辑时</option>
                <option value="2">仅编辑引用记录时</option>

            </select>
            <br/>仅编辑引用记录时适用于”嵌套表格2“宏控件选取的记录
        </td>
    </tr>
        <tr>
            <th><span>提示</span></th>
            <th><span>开关</span></th>
        </tr>
        <tr>
            <td>
                <textarea id="tip" name="tip" style="width:250px; height:100px"></textarea>
            </td>
            <td>
                <label class="radio"><input id="orgswitch0" checked="checked" name="switch" type="radio"> 否 </label>
                <label class="radio"><input id="orgswitch1" name="switch" type="radio"> 是 </label>
            </td>
        </tr>
    </table>
</div>
<script type="text/javascript">
var oNode = null,thePlugins = 'checkbox';
window.onload = function() {
    if( UE.plugins[thePlugins].editdom ){
        oNode = UE.plugins[thePlugins].editdom;
		
        var gTitle=oNode.getAttribute('title').replace(/&quot;/g,"\"");
        var gName=oNode.getAttribute('name').replace(/&quot;/g,"\"");
        var gDesc = oNode.getAttribute("description");
        if (gDesc!=null)
        	gDesc = gDesc.replace(/&quot;/g,"\"");
        var present = oNode.getAttribute("present");
        var gTip = oNode.getAttribute("tip");
        if (gTip == null) {
            gTip = '';
        }
        var gReadOnlyType = oNode.getAttribute("readOnlyType");
        if (gReadOnlyType == null) {
            gReadOnlyType = '';
        }

        var isReadOnly = oNode.getAttribute("readonly");
        if (isReadOnly != null) {
            $G('isReadOnly').checked = true;
        }
        else {
            $G('isReadOnly').checked = false;
        }

        $G('orgname').value = gName;
        $G('orgtitle').value = gTitle;
        $G('description').value = gDesc;
		
		$G('orgname').setAttribute("readonly", true);

		if (present) {
		    var ary = present.split("|");
		    if (ary!=null && ary.length==2) {
                $G('present0').value = ary[0];
                $G('present1').value = ary[1];
            }
        }

        var checked = oNode.getAttribute('checked');
		if (checked!=null) {
			checked = true;
		}
        checked ? $G('orgchecked1').checked = true : $G('orgchecked0').checked = true;

        var switchAttr = oNode.getAttribute('switch');
        if (switchAttr!=null && switchAttr=='true') {
            switchAttr = true;
        } else {
            switchAttr = false;
        }
        switchAttr ? $G('orgswitch1').checked = true : $G('orgswitch0').checked = true;

		$G('tip').value = gTip;
		$G('readOnlyType').value = gReadOnlyType;
    }
}
dialog.oncancel = function () {
    if( UE.plugins[thePlugins].editdom ) {
        delete UE.plugins[thePlugins].editdom;
    }
};
dialog.onok = function (){
    var gName=$G('orgname').value.replace(/\"/g,"&quot;");
    if(gName.value==''){
        alert('请输入控件字段');
        return false;
    }
	var gTitle=$G('orgtitle').value.replace(/\"/g,"&quot;");
    if(gTitle.value==''){
        alert('请输入控件名称');
        return false;
    }	
    var gDesc = $G('description').value.replace(/\"/g,"&quot;");
    var gTip = $G('tip').value;
    var gReadOnlyType = $G('readOnlyType').value;

    if( !oNode ) {
        try {
            oNode = createElement('input',gName);
            oNode.setAttribute('title',gTitle);
            oNode.setAttribute('cwsPlugins',thePlugins );
            oNode.setAttribute('type','checkbox');
            if ($G('orgchecked1').checked) {
                oNode.setAttribute('checked','');
            } else {
                oNode.checked = false;
            }
            if ($G('orgswitch1').checked) {
                oNode.setAttribute('switch', true);
                oNode.setAttribute('class', 'z-input-beautiful');
            } else {
                oNode.setAttribute('switch', false);
                oNode.setAttribute('class', '');
            }
            oNode.setAttribute("description", gDesc);
			
			oNode.value = "1";
			oNode.setAttribute("canNull", "1");
			oNode.setAttribute("present", $G('present0').value + "|" + $G('present1').value);
            oNode.setAttribute("tip", gTip);

            if ($G('isReadOnly').checked) {
                oNode.setAttribute("readonly", "readonly");
                oNode.setAttribute("onclick", "return false;");
            }
            else {
                oNode.removeAttribute("readonly");
                oNode.removeAttribute("onclick");
            }
            oNode.setAttribute('readOnlyType', gReadOnlyType);

            editor.execCommand('insertHtml',oNode.outerHTML);
            return true ;
        } catch ( e ) {
            try {
                editor.execCommand('error');
            } catch ( e ) {
                alert('控件异常！');
            }
            return false;
        }
    } else {
        oNode.setAttribute('title',gTitle);
        if ($G('orgchecked1').checked) {
            oNode.setAttribute('checked','');
        } else {
            oNode.removeAttribute('checked');
        }
        oNode.setAttribute('description', gDesc);
        oNode.setAttribute("present", $G('present0').value + "|" + $G('present1').value);
        oNode.setAttribute("tip", gTip);
        if ($G('isReadOnly').checked) {
            oNode.setAttribute("readonly", "readonly");
            oNode.setAttribute("onclick", "return false;");
        }
        else {
            oNode.removeAttribute("readonly");
            oNode.removeAttribute("onclick");
        }
        if ($G('orgswitch1').checked) {
            oNode.setAttribute('switch', true);
            oNode.setAttribute('class', 'z-input-beautiful');
        } else {
            oNode.setAttribute('switch', false);
            oNode.setAttribute('class', '');
        }
        oNode.setAttribute('readOnlyType', gReadOnlyType);

        delete UE.plugins[thePlugins].editdom;
        return true;
    }
};
</script>
</body>
</html>